<?php
namespace Admin\Controller;
use Think\Controller;
class GuahaoController extends AdminController {
    public function index(){
        $pMO = M('guahao');  
        $tCount = $pMO->count();
        $tPage = new \Think\Page($tCount,25);
        $tShow = $tPage->show();
        $tData = $pMO->order('id desc')->limit($tPage->firstRow.','.$tPage->listRows)->select();
        $this->assign('tPage',$tShow);// 赋值分页输出
        $this->assign('tData' , $tData);
        $this->display();
    }
    public function edit(){
        $tTime = time(); 

        $pId = I('id' , '' , 'intval'); 
        $tMO = M('guahao');
        if(empty($pId)){
            $this->error('ID不能为空');
        }

        if(IS_POST){
            $pRemark = I('remark' , '' , 'htmlspecialchars'); 
            $pStatus = I('status' , '' , 'int'); 

            $tData = array(
                'remark' => $pRemark,
                'updated' => $tTime,
                'status' => $pStatus,
            );
            if(!$tMO->where('id='.$pId)->save($tData)){
                $this->error('提交失败'); 
            }
            $this->success('处理成功', 'index');
            exit;
        }
        $tRow = $tMO->where('id='.$pId)->find();
        $this->assign('tRow' , $tRow);
        $this->display();
    }
    public function del(){
        $pId = I('id' , 0 , 'int'); 
        if(empty($pId)){
            $this->error('ID不能为空'); 
        }

        $tMO = M('guahao');
        $tData = array(
            'status' => 2, 
        );
        if(!$tMO->where('id = ' .$pId)->save($tData)){
            $this->error('处理失败'); 
        }
        $this->success('处理成功', U(MODULE_NAME. '/Guahao/index'));
    }
    public function delall(){
        $tIdarr = I('key',0 , 'intval');  
        if (!is_array($tIdarr)) {
            $this->error('请选择要彻底作废的项');
        }
        $tWhere = array('id' => array('in', $tIdarr));
        $tMO = M('guahao');
        $tData = array(
            'status' => 2, 
        );

        if(!$tMO->where($tWhere)->save($tData)){
            $this->error('处理失败'); 
        }

        $this->success('处理成功', U(MODULE_NAME. '/Guahao/index'));
    }

}
